package com.chushouya.manager.dao.repository;


import com.general.framework.core.enums.DelFlagEnum;
import com.general.framework.core.exception.Ex;
import com.general.framework.core.lang.Strings;
import com.general.framework.core.schema.PageResult;
import com.general.framework.data.mybatis.BaseRepository;
import com.chushouya.manager.dao.entity.BonusTypeEntity;
import com.chushouya.manager.dao.mapper.BonusTypeEntityMapper;
import com.chushouya.manager.dto.admin.bonustype.BonusTypeQuery;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Repository
public class BonusTypeRepository extends BaseRepository<BonusTypeEntityMapper, BonusTypeEntity, Long> {

    /**
     * 查询红包分页
     */
    public PageResult<BonusTypeEntity> selectPage(BonusTypeQuery query) {
        return this.selectPage(query, buildExample(query));
    }

    public List<BonusTypeEntity> selectList(BonusTypeQuery query) {
        return this.selectByExample(this.buildExample(query));
    }

    private Example buildExample(BonusTypeQuery query) {
        Example example = buildExample();
        if (Strings.isNotBlank(query.getTypeName())) {
            example.and().andLike("typeName", "%" + query.getTypeName() + "%");
        }
        example.and().andEqualTo("delFlag", DelFlagEnum.normal.getValue());
        example.orderBy("typeId").desc();
        return example;
    }

    public List<BonusTypeEntity> selectByMark(String mark) {
        Example example = buildExample();
        example.and().andEqualTo("mark", mark);
        return selectByExample(example);
    }

    public void updateSendNumber(Long bonusTypeId, Integer quantity) {
        if (bonusTypeId == null || quantity == null) {
            throw Ex.violation("更新红包发送数量异常, 非法参数");
        }
//        mapper.updateSendNumber(bonusTypeId, quantity);
    }

    public void updateReceiveNumber(Long bonusTypeId, Integer quantity) {
        if (bonusTypeId == null || quantity == null) {
            throw Ex.violation("更新红包领取数量异常, 非法参数");
        }
//        mapper.updateSendNumber(bonusTypeId, quantity);
    }

}
